# from lxml import etree
from lxml import etree

# lxml是XML和HTML的解析器，其主要功能是解析和提取XML和HTML中的数据

# nodename                              选中名为nodename的元素
# /                                     从根节点选取
# //                                    从匹配选择的当前节点选择文档中的节点，不考虑他的位置
# .                                     选取当前节点
# ..                                    选取当前节点的父节点
# @                                     选取属性
# text()                                获取文本
# string()                              获取文本
# *                                     选取所有节点
# @*                                    选取所有属性值
# node()                                选取任何节点
# |                                     '或' 两边写不同规则，分别进行匹配
#
# 节点修饰语法
# /a[@lang='eng']                       选取lang属性为eng的a元素
# /a[1]                                 选取第一个a元素
# /a[last()]                            选取最后一个a元素
# a[last()-1]                           选取倒数第二个a元素
# a[position()>1]                       从第二个a元素开始选取
# a[text()="aaa"]                       选取所有文本为aaa的元素
# a[price>35.00]                        选取所有peice大于35.00的a元素
# a[contains(@id, 'aa')]                选中所有包含的标签的id有aa部分的a标签
# a[contains(text(), "aa")]             选取所有包含aa文本的a标签

html = '''
<div class="middle_2">
	<div class="mi_d1">
		<div class="mi-lr">
			<a class="mi_tit" data-a=100 href="//huodong.4399.com/yizhou/">专辑</a>
			<div class="mi_d">
			    <span><a href="https://y.4399.com/" class="fb6"><b>云游戏</b></a>
			    </span><span><a href="/pcgame/">热游推荐</a></span>
			    <span><a href="/flash/">最新游戏</a></span>
			    <span><a href="/special/1.htm" class="fb6"><b>双人小游戏</b></a></span>
			    <span><a href="/special/148.htm">无敌版</a></span>
			    <span><a href="/special/219.htm" class="fb6">单人</a></span>
			    <span><a href="/special/241.htm">冰火人</a></span>
			    <span><a href="/special/225.htm" class="fb6">三人</a></span>
			</div>
		</div>
		<div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/13_1.htm">儿童</a>
			<div class="mi_d">
                <span><a href="/special/232.htm">填颜色</a></span>
                <span><a href="/special/286.htm">小马宝莉</a></span>
                <span><a href="/special/17.htm">海绵宝宝</a></span>
                <span><a href="/special/293.htm">组装游戏</a></span>
                <span><a href="/special/182.htm">朵拉</a></span>
                <span><a href="/special/202.htm">学习</a></span>
                <span><a href="/special/252.htm">玩具</a></span>
                <span><a href="/special/269.htm">托马斯</a></span>
            </div>
		</div>
	</div>
	<div class="mi_d2">
		 <div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/2_1.htm">动作</a>
			<div class="mi_d"><span><a href="/special/13.htm">格斗</a></span><span><a href="/special/242.htm">乐高</a></span><span><a href="/special/270.htm">男生游戏</a></span><span><a href="/special/33.htm">三国</a></span><span><a href="/special/258.htm" class="fb6">功夫</a></span><span><a href="/special/95.htm">变形金刚</a></span><span><a href="/special/136.htm">火柴人</a></span><span><a href="/special/224.htm">西游记</a></span><span><a href="/special/235.htm">机器人</a></span></div>
		  </div>
		  <div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/4_1.htm">射击</a>
			<div class="mi_d"><span><a href="/special/238.htm">穿越防线</a></span><span><a href="/special/208.htm">狙击手</a></span><span><a href="/special/10.htm">反恐精英</a></span><span><a href="/special/126.htm">大炮</a></span><span><a href="/special/16.htm">战斗机</a></span><span><a href="/special/128.htm">特种兵</a></span><span><a href="/special/29.htm">坦克</a></span><span><a href="/special/121.htm">枪战特警</a></span></div>
		</div>
	</div>
	<div class="mi_d1">
		<div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/5_1.htm">益智</a>
			<div class="mi_d"><span><a href="/special/8.htm" class="fb6"><b>连连看</b></a></span><span><a href="/special/212.htm">解谜</a></span><span><a href="/special/173.htm">拼图</a></span><span><a href="/special/63.htm">迷宫</a></span><span><a href="/special/98.htm">大富翁</a></span><span><a href="/special/60.htm">找茬</a></span><span><a href="/special/59.htm" class="fb6">塔防</a></span><span><a href="/special/168.htm">找东西</a></span><span><a href="/special/87.htm">麻将</a></span><span><a href="/special/218.htm">小火车</a></span></div>
		</div>
		<div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/12_1.htm">休闲</a>
			<div class="mi_d"><span><a href="/special/143.htm" class="fb6">斗地主</a></span><span><a href="/special/66.htm">祖玛</a></span><span><a href="/special/34.htm">黄金矿工</a></span><span><a href="/special/64.htm">消消看</a></span><span><a href="/special/79.htm">吃豆豆</a></span><span><a href="/special/62.htm">泡泡龙</a></span><span><a href="/special/125.htm">直升机</a></span><span><a href="/special/152.htm">农场</a></span><span><a href="/special/71.htm">吃东西</a></span></div>
		</div>
	</div>
	<div class="mi_d2">
		 <div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/3_1.htm">体育</a>
			<div class="mi_d"><span><a href="/special/28.htm">赛车</a></span><span><a href="/special/96.htm">卡丁车</a></span><span><a href="/special/164.htm">越野车</a></span><span><a href="/special/37.htm">自行车</a></span><span><a href="/special/167.htm">汽车</a></span><span><a href="/special/100.htm">停车</a></span><span><a href="/special/35.htm">篮球</a></span><span><a href="/special/38.htm" class="fb6"><b>足球</b></a></span><span><a href="/special/118.htm">过山车</a></span><span><a href="/special/31.htm">台球</a></span></div>
		  </div>
		  <div class="mi-lr">
			<a class="mi_tit" href="/flash_fl/6_1.htm">冒险</a>
			<div class="mi_d"><span><a href="/special/172.htm">中文精选</a></span><span><a href="/special/93.htm" class="fb6">大鱼吃小鱼</a></span><span><a href="/special/277.htm">动漫游戏</a></span><span><a href="/special/89.htm">冒险岛</a></span><span><a href="/special/120.htm">忍者</a></span><span><a href="/special/259.htm">跑酷</a></span><span><a href="/special/124.htm">战士</a></span><span><a href="/special/90.htm" class="fb6">闯关</a></span><span><a href="/special/260.htm">3D游戏</a></span></div>
		</div>
	</div>
	<div class="mi_d1">
		<a class="mi_tit" href="/special/195.htm">女生</a>
		<div class="mi_g"><span><a href="/special/23.htm">阿sue</a></span><span><a href="//zuopin.4399.com/tyq/">美图</a></span><span><a href="/special/255.htm">美人鱼</a></span><span><a href="/special/169.htm">公主</a></span><span><a href="/special/204.htm">古代换装</a></span><span><a href="/special/7.htm">做饭</a></span><span><a href="/special/254.htm">精灵</a></span><span><a href="/special/94.htm">化妆</a></span><span><a href="/special/27.htm">美甲</a></span><span><a href="/special/105.htm">婚纱</a></span><span><a href="/special/154.htm">美发</a></span><span><a href="/special/112.htm">餐厅</a></span><span><a href="/special/108.htm">蛋糕</a></span><span><a href="/special/106.htm">礼服</a></span><span><a href="/special/107.htm">布置</a></span><span><a href="/special/109.htm">宠物</a></span><span><a href="/special/103.htm">购物</a></span><span><a href="/special/114.htm">芭比</a></span><span><a href="/special/171.htm">制作</a></span><span><a href="/special/263.htm">养成</a></span><span><a href="/special/153.htm">宝贝</a></span><span><a href="/special/115.htm">时尚</a></span><span><a href="/special/110.htm">打工挣钱</a></span></div>
	</div>
	<div class="mi_d2">
		<a class="mi_tit" href="/special/good.htm">合辑</a>
		<div class="mi_g">
			<div class="caro" id="s1">
			    <ul><li><a onclick="return tracead('www_index_txt_1');" href='/flash/234014.htm'>4399仙侠神域 炼气化神，三花聚顶</a></li><li><a onclick="return tracead('www_index_txt_2');" href='//my.4399.com/yxpmxy/'>4399飘渺西游 神兽旺福，登录即送</a></li><li><a onclick="return tracead('www_index_txt_3');" href='/flash/242304.htm'>4399刺沙 热血升级，燃爆沙城</a></li><li><a onclick="return tracead('www_index_txt_4');" href='//my.4399.com/yxtjfb/'>4399铁甲风暴 百种战场，兵甲云集</a></li></ul></div><span><a href="//my.4399.com/yxbzsc/" class="fb6">百战沙城</a></span><span><a href="//news.4399.com/ytzg/">以太之光</a></span><span><a href="/flash/242001.htm" class="fb6">弹弹堂2</a></span><span><a href="/flash/233528.htm">白蛇传奇</a></span><span><a href="//news.4399.com/aoqi/" class="fb6"><b>奥奇传说</b></a></span><span><a href="//my.4399.com/yxpmxy/">飘渺西游</a></span><span><a href="//my.4399.com/yxqjz/">三国群将传</a></span><span><a href="//my.4399.com/yxpkt/" class="fb6"><b>皮卡堂</b></a></span><span><a href="https://my.4399.com/yxxtkzw/">天空之舞</a></span><span><a href="//my.4399.com/yxssjj2/" class="fb6"><b>生死狙击2</b></a></span><span><a href="/flash/242304.htm">刺沙</a></span>		</div>
	</div>
	<div class="mi_d3">
		<a class="more" href="//web.4399.com/">更多&gt;&gt;</a>
		<a class="game_w" href="//web.4399.com/">网页游戏</a>
		<div class="mi_web"><span><a href="//news.4399.com/qiu/" class="f38">玩个球</a></span><span><a href="//my.4399.com/yxsgkd/" class="f38">三国快打</a></span><span><a href="/flash/12439.htm" class="f38">弹弹堂</a></span><span><a href="https://ssjj.4399.com/" class="fb6"><b>生死狙击</b></a></span><span><a href="//my.4399.com/yxwjcq/" class="f38">维京传奇</a></span><span><a href="https://my.4399.com/yxmsdzls/" class="fb6">美食大战老鼠</a></span><span><a href="//my.4399.com/yxtouch/" class="f38">Touch触动</a></span><span><a href="https://news.4399.com/hxjy/" class="fb6"><b>火线精英</b></a></span><span><a href="//news.4399.com/aoyazhiguang/" class="f38">奥雅之光</a></span><span><a href="/flash/10379.htm" class="f38">奥比岛</a></span><span><a href="/flash/35538.htm" class="fb6">奥拉星</a></span><span><a href="//my.4399.com/yxlq/" class="f38">龙泣</a></span><span><a href="https://my.4399.com/yxsgs/" class="fb6">三国杀</a></span><span><a href="/flash/240970.htm" class="f38">星神纪元</a></span><span><a href="/flash/234014.htm" class="f38">仙侠神域</a></span></div>
	</div>
	<div class="mi_d2" id="a">
		<a class="more" href="//h.4399.com/">更多&gt;&gt;</a>
		<a class="h5_w" href="//h.4399.com/">H5游戏</a>
		<div class="mi_g">
		    <span><a href="/flash/236489.htm" class="fb6">冒险大作战</a></span>
		    <span><a href="/flash/240282.htm" class="f38">幻想圣域</a></span>
		    <span><a href="/flash/238466.htm" class="f38">土豆英雄</a></span>
		    <span><a href="/flash/224390.htm" class="f38">盛世芳华</a></span>
		    <span><a href="/flash/240287.htm" class="f38">战机大作战</a></span>
		    <span><a href="/flash/238912.htm" class="f38">怪兽宝贝</a></span>
		    <span><a href="/flash/237903.htm" class="f38">明日大亨</a></span>
		    <span><a href="/flash/225563.htm" class="f38">鲜花小镇</a></span>
		    <span><a href="/flash/233930.htm" class="f38">虫虫大作战</a></span>
		    <span><a href="/flash/198091.htm" class="f38">小小首富</a></span>
		    <span><a href="/flash/204765.htm" class="f38">暴走英雄坛</a></span>
		    <span><a href="/flash/224122.htm" class="f38">三国杀H5</a></span>
		    <span><a href="/flash/201130.htm" class="f38">怼怼三国</a></span>
		</div>
	</div>
</div>
'''

# 通过etree.HTML直接将字符串实例转化为element对象
html = etree.HTML(html)
print(html.xpath("//div[@id='a']/div/span/a/text()"))


















